const textMsgMW = require('express').Router()

//基础会话创建
textMsgMW.route('/wx')
    .post(async(req, res, next) => {
        const mongoose = require('mongoose')
        const userSchema = require('../../model/userSchema')
        const User = mongoose.model('user', userSchema)
        //新建或查询用户数据库
        const user = await User.findOne({userID: req.jsonData.FromUserName[0]})
        //针对数据库未建立之前用户的账户建立
        if(!user) {
            const newUser = new User({
                userID: req.jsonData.FromUserName[0]
            })
            newUser.save()
            req.user = newUser
        } else {
            req.user = user
        }

        next()
    })

//每日经文中间件
textMsgMW.use(require('./textMsg/dailyVerseMW'))

//抗原信息房号处理中间件
textMsgMW.use(require('./textMsg/nATMW'))

//查看当日抗原信息中间件
textMsgMW.use(require('./textMsg/seeTodayNATMW'))

//其他文字中间件
textMsgMW.use(require('./textMsg/elseTextMW'))

module.exports = textMsgMW

